import { createRouter, createWebHistory } from 'vue-router'
const routes = [
  {
    path: "/",
    redirect: "/login"
  },
  {
    path: "/index",
    component: () => import('../views/index.vue'),
    children: [
      {
        path: 'userlist',
        component: () => import('../views/user/userList.vue')
      },
      {
        path: 'withdrawal',
        component: () => import('../views/check/withdrawal.vue')
      },
      
      {
        path: 'loginlist',
        component: () => import('../views/user/loginList.vue')
      },
      {
        path: 'wlist',
        component: () => import('../views/collection/wlist.vue')
      },
      {
        path: 'marquee',
        component: () => import('../views/infomation/marquee.vue')
      },
      // 过滤器
      {
        path: '/:pathMatch(.*)',
        component: () => import('../views/login.vue')
      },
      {
        path: 'opus',
        name: 'opus',
        component: () => import('../views/goods/Opus.vue')
      },
      {
        path: 'typelist',
        name: 'typelist',
        component: () => import('../views/goods/TypeList.vue')
      }, {
        path: 'marketorders',
        name: 'marketorders',
        component: () => import('../views/orders/MarketOrders.vue')
      },
      {
        path: 'artorders',
        name: 'artorders',
        component: () => import('../views/orders/ArtOrders.vue'),
      }
      ,
      {
        path: 'tokensList',
        name: 'tokensList',
        component: () => import('../views/goods/TokensList.vue')
      },
    ]
  },
  {
    path: "/login",
    component: () => import('../views/login.vue')

  }
]



const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
  linkActiveClass: 'active'
})

router.beforeEach((to,from) => {
  let token = window.sessionStorage.getItem("username");

  if(to.path==="/index"){
    if(token){
      return true;
    }else{
      return{
        path:"/login"
      }
    }
  }


})

export default router
